home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / ums / ums109_1.lha / Tools / SelectMail.LHA / SelectMail / SelectMail.c < prev    next >
C/C++ Source or Header  |  1993-04-04  |  7KB  |  230 lines

  1. /*
  2.  * SelectMail.c (adapted from SelectMail.mod)
  3.  *
  4.  * Use under UMS V9 ONLY!!!
  5.  *
  6.  */
  7.  
  8. #include <clib/ums_protos.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. UMSUserAccount account;
  13.  
  14. /* get UMS error number and print error text */
  15. void CheckErr(void)
  16. {
  17.  UMSError err;
  18.  
  19.  err=UMSErrNum(account);
  20.  
  21.  /* got an error? */
  22.  if (err != UMSERR_OK)
  23.   {
  24.    fprintf(stderr,"UMS-Error: %3d, '%s'\n",err,UMSErrTxt(account));
  25.    UMSLogout(account);
  26.    exit(20);
  27.   }
  28. }
  29.  
  30. int main(int argc, char *argv[])
  31. {
  32.  char *login,*passwd,*select;
  33.  UMSMsgNum result;
  34.  
  35.  if (argc<3)
  36.   {
  37.    fprintf(stderr,"Usage: %s <login> <passwd> [<select name>]\n",argv[0]);
  38.    exit(0);
  39.   }
  40.  
  41.  /* Read parameters */
  42.  login=argv[1];
  43.  passwd=argv[2];
  44.  if (argc>3)
  45.   select=argv[3]; /* select name is the same as login name */
  46.  else
  47.   select=login;
  48.  
  49.  /* log into UMS system */
  50.  if ((account=UMSLogin(login,passwd))==NULL)
  51.   {
  52.    fprintf(stderr,"Login failed.\n");
  53.    exit(20);
  54.   }
  55.  
  56.  /****************************************************************************
  57.    1. For all messages with
  58.  
  59.        (GlobalFlags & (ViewAccess|PostPoned|Old)) == ViewAccess
  60.  
  61.       set the local flag bit 0.
  62.  
  63.       These are all NEW messages, which can be seen by the user.
  64.  *****************************************************************************/
  65.  
  66.  printf("Looking for new messages: ");
  67.  fflush(stdout);
  68.  result=UMSSelectTags(account,UMSTAG_SelMask,       UMSUSTATF_ViewAccess |
  69.                                                     UMSUSTATF_PostPoned  |
  70.                                                     UMSUSTATF_Old,
  71.                               UMSTAG_SelMatch,      UMSUSTATF_ViewAccess,
  72.  
  73.                               UMSTAG_SelWriteLocal, TRUE,
  74.                               UMSTAG_SelSet,        (1L<<0),
  75.                               UMSTAG_SelUnset,      0,
  76.                               TAG_DONE);
  77.  printf("%d found.\n",result);
  78.  CheckErr();
  79.  
  80.  /****************************************************************************
  81.    2. For all messages with
  82.  
  83.        ToName field == select name
  84.  
  85.       set the local flag bit 1.
  86.  
  87.       These are all messages addressed to the user.
  88.  *****************************************************************************/
  89.  
  90.  printf("selecting by name: ");
  91.  fflush(stdout);
  92.  result=UMSSelectTags(account,UMSTAG_WToName,       select,
  93.  
  94.                               UMSTAG_SelWriteLocal, TRUE,
  95.                               UMSTAG_SelSet,        (1L<<1),
  96.                               UMSTAG_SelUnset,      0,
  97.                               UMSTAG_SelQuick,      TRUE,
  98.                               TAG_DONE);
  99.  printf("%d selected.\n",result);
  100.  CheckErr();
  101.  
  102.  /****************************************************************************
  103.    3. For all messages with
  104.  
  105.        (LocalFlags & (Bit 0 and Bit 1)) == (Bit 0 and Bit 1)
  106.  
  107.       set the local flag bit 4.
  108.  
  109.       This operation builds the intersection set of the operation 1 and 2,
  110.       thus setting the local flag bit 4 in all new messages, which are
  111.       addressed to the user.
  112.  *****************************************************************************/
  113.  
  114.  printf("  new messages amongst these: ");
  115.  fflush(stdout);
  116.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  117.                               UMSTAG_SelMask,       (1L<<0) | (1L<<1),
  118.                               UMSTAG_SelMatch,      (1L<<0) | (1L<<1),
  119.  
  120.                               UMSTAG_SelWriteLocal, TRUE,
  121.                               UMSTAG_SelSet,        (1L<<4),
  122.                               UMSTAG_SelUnset,      0,
  123.                               UMSTAG_SelQuick,      TRUE,
  124.                               TAG_DONE);
  125.  printf("%d selected.\n",result);
  126.  CheckErr();
  127.  
  128.  /****************************************************************************
  129.    4. For all messages with
  130.  
  131.        FromName field == select name
  132.  
  133.       set local flag bit 2.
  134.  
  135.       These are all messages written by the user.
  136.  *****************************************************************************/
  137.  
  138.  printf("looking for messages written by you: ");
  139.  fflush(stdout);
  140.  result=UMSSelectTags(account,UMSTAG_WFromName,     select,
  141.  
  142.                               UMSTAG_SelWriteLocal, TRUE,
  143.                               UMSTAG_SelSet,        (1L<<2),
  144.                               UMSTAG_SelUnset,      0,
  145.                               UMSTAG_SelQuick,      TRUE,
  146.                               TAG_DONE);
  147.  printf("%d found.\n",result);
  148.  CheckErr();
  149.  
  150.  /****************************************************************************
  151.    5. For all messages with a parent message and
  152.  
  153.        (parent's LocalFlags & Bit 2) == Bit 2
  154.  
  155.       set local flag bit 3.
  156.  
  157.       These are all replies to messages written by the user.
  158.  *****************************************************************************/
  159.  
  160.  printf("selecting replies to your msgs: ");
  161.  fflush(stdout);
  162.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  163.                               UMSTAG_SelParent,     TRUE,
  164.                               UMSTAG_SelMask,       (1L<<2),
  165.                               UMSTAG_SelMatch,      (1L<<2),
  166.  
  167.                               UMSTAG_SelWriteLocal, TRUE,
  168.                               UMSTAG_SelSet,        (1L<<3),
  169.                               UMSTAG_SelUnset,      0,
  170.                               UMSTAG_SelQuick,      TRUE,
  171.                               TAG_DONE);
  172.  printf("%d selected.\n",result);
  173.  CheckErr();
  174.  
  175.  /****************************************************************************
  176.    6. For all messages with
  177.  
  178.        (LocalFlags & (Bit 0 and Bit 3)) == (Bit 0 and Bit 3)
  179.  
  180.       set the local flag bit 4.
  181.  
  182.       This operation builds the intersection set of the operation 4 and 5,
  183.       thus setting the local flag bit 4 in all new messages, which are
  184.       replies to messages written by the user.
  185.  *****************************************************************************/
  186.  
  187.  printf("  new messages amongst these: ");
  188.  fflush(stdout);
  189.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  190.                               UMSTAG_SelMask,       (1L<<0) | (1L<<3),
  191.                               UMSTAG_SelMatch,      (1L<<0) | (1L<<3),
  192.  
  193.                               UMSTAG_SelWriteLocal, TRUE,
  194.                               UMSTAG_SelSet,        (1L<<4),
  195.                               UMSTAG_SelUnset,      0,
  196.                               UMSTAG_SelQuick,      TRUE,
  197.                               TAG_DONE);
  198.  printf("%d selected.\n",result);
  199.  CheckErr();
  200.  
  201.  /****************************************************************************
  202.    7. For all messages with
  203.  
  204.        (LocalFlags & Bit 4) == Bit 4
  205.  
  206.       set the selected user flag.
  207.  
  208.       This operation builds the union set of the operation 3 and 6, thus
  209.       setting the selected user flag in all new messages, which are either
  210.       messages addressed to the user or replies to messages written by the
  211.       user.
  212.       The news reader will now show these messages first.
  213.  *****************************************************************************/
  214.  
  215.  printf("totally selected: ");
  216.  fflush(stdout);
  217.  result=UMSSelectTags(account,UMSTAG_SelReadLocal,  TRUE,
  218.                               UMSTAG_SelMask,       (1L<<4),
  219.                               UMSTAG_SelMatch,      (1L<<4),
  220.  
  221.                               UMSTAG_SelSet,        UMSUSTATF_Selected,
  222.                               UMSTAG_SelUnset,      0,
  223.                               TAG_DONE);
  224.  printf("%d.\n",result);
  225.  CheckErr();
  226.  
  227.  UMSLogout(account);
  228.  return(0);
  229. }
  230.